﻿import { Component } from '@angular/core';
import {BookRepository} from './repository.model';
import { Book } from './book.model'
import {DatePipe, DecimalPipe, NgIf, NgStyle, NgSwitch, NgSwitchCase} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {Post} from './post/post';

@Component({
  selector: 'book',
  templateUrl: './book.component.html',
  imports: [
    NgStyle,
    DecimalPipe,
    DatePipe,
    NgIf,
    NgSwitch,
    NgSwitchCase,
    FormsModule,
    Post
  ],
  styleUrl: './book.component.css'
})

export class BookComponent{
  model:BookRepository = new BookRepository();

  newBook : Book = new Book();
  get jsonBook(){
    return JSON.stringify(this.newBook);
  }
  addBook(b:Book){
    console.log("New book is:" +this.jsonBook);
  }

  getValidationErrors(info:any){
    let ctrlName:string = info.name;
    let message:string[]= [];
    if(info.errors){
      for(let errorName in info.errors){
        switch (errorName){
          case "required":
            message.push("you must enter a $(ctrlName)");
            break;
          case "minlength":
            message.push("you must enter min 3 characters");
            break;
        }
      }
    }
    return message;
  }
  // log(info:string){
  //   console.log(info);
  // }
}

//
// export class BookComponent{
//   names:string ='Angular Pipes';
//   price:number=190.89395;
//   today:number =Date.now()
//
//
//
//
//   model:BookRepository = new BookRepository();
//   color:string ="yellow";
//   book:Book = this.model.getBookId(1);
//   disabled = true;
//   getClassBinding(id:number):string{
//     let book = this.model.getBookId(id);
//     // @ts-ignore
//     return (book.price >= 20  ? "bg-primary" : "bg-info");
//   }
//
//   getStyleBinding(id:number):Object{
//     let book = this.model.getBookId(id);
//     return{
//       fontSize:"40px",
//       color:"orange"
//     }
//   }
//
//   onClick(){
//     console.log('button was clicked');
//   }
//
//   onKeyUp($event: { keyCode: number; }){
//     if($event.keyCode === 13){
//       console.log('Pressed enter key');
//     }
//   }
//
//   protected readonly getComputedStyle = getComputedStyle;
//
// }
